winbrew_windows\deployment\msix/
mod.rs

1mod install;
2mod remove;
3
4pub use install::install;
5pub use remove::remove;
6
7use anyhow::{Context, Result};
8use windows::Management::Deployment::PackageManager;
9
10/// Resolve the installed full package name for an MSIX package name.
11///
12/// The lookup accepts either a package full name or a package family name.
13/// If exactly one installed package matches, its full name is returned.
14/// Zero matches and ambiguous matches both return an error so the caller can
15/// handle the mismatch explicitly.
16pub fn installed_package_full_name(package_name: &str) -> Result<String> {
17    let package_manager = PackageManager::new().context("failed to create package manager")?;
18    let matching_full_names = remove::matching_package_full_names(&package_manager, package_name)?;
19
20    match matching_full_names.as_slice() {
21        [full_name] => Ok(full_name.to_string()),
22        [] => anyhow::bail!("no installed msix package matched '{package_name}'"),
23        _ => anyhow::bail!("multiple installed msix packages matched '{package_name}'"),
24    }
25}